<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	include("_include.user.judge.php");
	$kboy_user = $_SESSION['kboy_user'];
	$kboy_userid = $_SESSION['kboy_userid'];
	
	$action = chkstr(trim($_REQUEST['action']));
	$user_yemail = chkstr(trim($_REQUEST['user_yemail']));
	$user_email = chkstr(trim($_REQUEST['user_email']));
	$user_emailcode = chkstr(trim($_REQUEST['user_emailcode']));
	if($action == "edit"){
	
		// 邮箱验证
		if(!isEmail($user_yemail)){
			echo erro("原邮箱格式错误！");
		}
		if(!isEmail($user_email)){
			echo erro("邮箱格式错误！");
		}
		
		// 验证码验证
		if(strlen($user_emailcode)<1){
			echo erro("请正确输入验证码！");
		}
		if($user_email != $_SESSION['EmailName']){
			echo erro("请正确输入验证码！");
		}
		if($user_emailcode != $_SESSION['EmailCode']){
			echo erro("请正确输入验证码！");
		}
		
		
		$is_reguser = getNewsNums("kboy_user","user_email='$user_email'");
		if($is_reguser >0){
			echo erro("该邮箱已被注册！");
		}
		
		$mysql = new sqlstr("kboy_user"); 
		$mysql -> set("user_email",$user_email);
		$news_sql = $mysql -> updateSql("uid=$kboy_userid");
		$news_res = mysql_query($news_sql);
		if($news_res){
			$_SESSION['kboy_user'] = "";
			$_SESSION['kboy_userid'] = "";
			$_SESSION['EmailName'] = "";
			$_SESSION['EmailCode'] = "";
			echo ok("操作成功","login.php");
		}else{
			echo erro("服务器内部错误");
		}
	
	}else if($action == "add"){
		if(!isEmail($user_email)){
			echo erro("邮箱格式错误！");
		}
		
		// 验证码验证
		if(strlen($user_emailcode)<1){
			echo erro("请正确输入验证码！");
		}
		if($user_email != $_SESSION['EmailName']){
			echo erro("请正确输入验证码！");
		}
		if($user_emailcode != $_SESSION['EmailCode']){
			echo erro("请正确输入验证码！");
		}
		
		
		$is_reguser = getNewsNums("kboy_user","user_email='$user_email'");
		if($is_reguser >0){
			echo erro("该邮箱已被注册！");
		}
		
		$mysql = new sqlstr("kboy_user"); 
		$mysql -> set("user_email",$user_email);
		$news_sql = $mysql -> updateSql("uid=$kboy_userid");
		$news_res = mysql_query($news_sql);
		if($news_res){
			$_SESSION['kboy_user'] = "";
			$_SESSION['kboy_userid'] = "";
			$_SESSION['EmailName'] = "";
			$_SESSION['EmailCode'] = "";
			echo ok("操作成功","login.php");
		}else{
			echo erro("服务器内部错误");
		}
	
	}else{
		echo erro("参数错误");
	}
?>